package generic.generator;

import utils.Log;

import java.util.Iterator;

public class IterableFibonacci extends Fibonacci implements Iterable<Integer> {

    private int size;

    public IterableFibonacci(int size) {
        this.size = size;
    }


    @Override
    public Iterator<Integer> iterator() {
        return new Iterator<Integer>() {
            @Override
            public boolean hasNext() {
                return size > 0;
            }

            @Override
            public Integer next() {
                size--;
                return IterableFibonacci.this.next();
            }
        };
    }


    public static void main(String[] args) {
        for (Integer i : new IterableFibonacci(18)) {
            Log.vn(i);
        }

    }
}
